package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.MajorDto;
import com.grademaster.dto.MajorPageDto;
import com.grademaster.entity.Majors;
import com.grademaster.service.MajorsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/majors")
@Api(tags = "专业相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class MajorsController {

    @Autowired
    private MajorsService majorsService;

    @ApiOperation("获取所有专业信息")
    @GetMapping("/getAllMajors")
    public R getAllMajors() {
        return majorsService.getAllMajors();
    }

    @ApiOperation("获取所有专业分页信息")
    @GetMapping("/getAllMajorsByPage")
    public R getAllMajorsByPage(MajorPageDto majorPageDto) {
        return majorsService.getAllMajorsByPage(majorPageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(MajorPageDto majorPageDto){
        return majorsService.exportExcel(majorPageDto);
    }

    @ApiOperation("添加或修改专业")
    @PostMapping("/addOrEditMajor")
    public R addOrEditMajor(@RequestBody Majors majors) {
        return majorsService.addOrEditMajor(majors);
    }

    @ApiOperation("删除学院")
    @DeleteMapping("/deleteMajor/{majorId}")
    public R deleteMajor(@PathVariable("majorId") String majorId) {
        return majorsService.deleteMajor(majorId);
    }

}
